using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DostavnaSluzba
{
    public partial class Form1 : Form
    {
        public LoginForm lfrm;
        public Stranke sfrm;
        public bool loggedIn = false;
        public Form1()
        {
            InitializeComponent();
            lfrm = new LoginForm();
            //lfrm.MdiParent = this;
        }

        private void izhodToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            Application.Exit();
        }

        private void krajiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            KrajiForm kfrm = new KrajiForm();
            kfrm.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           // lfrm.Show();
            //lfrm.BringToFront();     
        }

        private void prijavaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!this.loggedIn)
            {
                lfrm.ShowDialog(this);
                lfrm.BringToFront();
                
                if (lfrm.rezultat)
                {
                    this.loggedIn = true;
                    this.doLogin();
                }
                else
                {
                    //notok
                }
            }
            else
            {
                this.loggedIn = false;
                this.doLogout();
                lfrm = new LoginForm();
            }
                 
        }
        private void doLogin()
        {
            lfrm.Close();
            this.Activate();
            novoNarociloToolStripMenuItem.Enabled = true;
            stranketoolStripMenuItem1.Enabled = true;
            sifrantiToolStripMenuItem.Enabled = true;
            porocilaToolStripMenuItem.Enabled = true;
            prijavaToolStripMenuItem.Text = "Odjava";
            this.Cursor = Cursors.AppStarting;
            Narocila narocilaForm = new Narocila();
            narocilaForm.MdiParent = this;
            narocilaForm.Show();
            this.Cursor = Cursors.Default;
        }
        private void doLogout()
        {
            foreach (Form f in this.MdiChildren)
            {
                f.Close();
            }
            novoNarociloToolStripMenuItem.Enabled = false;
            stranketoolStripMenuItem1.Enabled = false;
            sifrantiToolStripMenuItem.Enabled = false;
            porocilaToolStripMenuItem.Enabled = false;
            prijavaToolStripMenuItem.Text = "Prijava";
           
        }

        private void stranketoolStripMenuItem1_Click(object sender, EventArgs e)
        {
            sfrm = new Stranke();
            sfrm.Show();
        }
    }
}